### Function Description

Create or update Cron Job; Create Cron Job, Cron Job status is paused by default, you can call update_cron_status
interface to turn it on if needed.

### Request Parameters

#### Interface parameters

| Fields          | Type   | Required | Description                                                                                                                                                                                                                                                                                 |
|-----------------|--------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| bk_scope_type   | string | yes      | Resource scope type. Optional values: biz - Business，biz_set - Business Set                                                                                                                                                                                                                 |
| bk_scope_id     | string | yes      | Resource scope ID. Corresponds to bk_scope_type, which means business ID or business set ID                                                                                                                                                                                                 |
| bk_biz_id       | long   | yes      | Deprecated. Business ID. This field has been deprecated and replaced by the field bk_scope_type+bk_scope_id                                                                                                                                                                                 |
| job_plan_id     | long   | yes      | Job Plan ID of the job to be executed regularly                                                                                                                                                                                                                                             |
| id              | long   | no       | Cron Job ID, when updating a Cron Job, you must pass this value Cron Job                                                                                                                                                                                                                    |
| name            | string | no       | Cron job name, required for new creation and optional for modification                                                                                                                                                                                                                      |
| expression      | string | no       | Timing rules for Cron Job crontab, optional when modifying. The meaning of each field is: minute hour day month week, for example: 0/5 * * * * means execute every 5 minutes. caution: ? not supported. This field and execute_time cannot be empty at the same time when creating Cron Job |
| execute_time    | long   | no       | Single execution execution time, Unix timestamp, this field and expression cannot be empty at the same time when creating Cron Job                                                                                                                                                          |
| global_var_list | array  | no       | Global variable information, you can use the Query Job Plan Details interface to query the variable information which can be set for the plan                                                                                                                                               |

#### global_var

| Fields | Type   | Required | Description                                                                                                   |
|--------|--------|----------|---------------------------------------------------------------------------------------------------------------|
| id     | long   | no       | Global variable id, unique identification. If the id is empty, then name is used as the unique identification |
| name   | string | no       | Global variable name                                                                                          |
| value  | string | no       | Character, password, value of global variable of array type                                                   |
| server | object | no       | The value of the host type global variable                                                                    |

#### server

| Fields             | Type  | Required | Description                                                                                                                                                                                              |
|--------------------|-------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| host_id_list       | array | no       | Host ID list                                                                                                                                                                                             |
| ip_list            | array | no       | Static IP list, see ip for definition. ***Deprecated, it is recommended to use the host_id_list parameter***; if host_id_list and ip_list exist at the same time, the ip_list parameter will be ignored. |
| dynamic_group_list | array | no       | Dynamic grouping list, see dynamic_group for definition                                                                                                                                                  |
| topo_node_list     | array | no       | Dynamic topo node list, see topo_node for definition                                                                                                                                                     |

#### ip

| Fields      | Type   | Required | Description |
|-------------|--------|----------|-------------|
| bk_cloud_id | int    | yes      | BK-Net ID   |
| ip          | string | yes      | IP Address  |

#### topo_node

| Fields    | Type   | Required | Description                                                                                |
|-----------|--------|----------|--------------------------------------------------------------------------------------------|
| id        | long   | yes      | Dynamic topo node ID, corresponding to bk_inst_id in CMDB API                              |
| node_type | string | yes      | Dynamic topo node type, corresponding to bk_obj_id in CMDB API, such as "module" and "set" |

### Example of request

- POST

#### 1.Create  Cron Job

```json
{
    "bk_scope_type": "biz",
    "bk_scope_id": "1",
    "execute_time": 0,
    "expression": "0 0/5 * * *",
    "job_plan_id": 1023060,
    "name": "test API",
    "global_var_list": [
        {
            "name": "stringVar",
            "value": "value11112"
        },
        {
            "name": "nsVar",
            "value": "nsvalue11112"
        },
        {
            "name": "secretVar",
            "value": "secretvalue11112"
        },
        {
            "name": "dictVar",
            "value": "([\"var1\"]=1, [\"var2\"]=2)"
        },
        {
            "name": "indexArrVar",
            "value": "(2 3 4)"
        },
        {
            "name": "hostVar",
            "server": {
                "host_id_list": [
                    1,
                    2,
                    3
                ]
            }
        }
    ]
}
```

#### 2.Update  Cron Job

```json
{
    "id": 1000064,
    "bk_scope_type": "biz",
    "bk_scope_id": "1",
    "execute_time": 0,
    "expression": "0 0/5 * * *",
    "job_plan_id": 1023060,
    "name": "test API",
    "global_var_list": [
        {
            "name": "stringVar",
            "value": "value111333312"
        },
        {
            "name": "nsVar",
            "value": "nsvalue111333312"
        },
        {
            "name": "secretVar",
            "value": "secretvalue111333312"
        },
        {
            "name": "dictVar",
            "value": "([\"var1\"]=1, [\"var2\"]=2)"
        },
        {
            "name": "indexArrVar",
            "value": "(22 3 4)"
        },
        {
            "name": "hostVar",
            "server": {
                "host_id_list": [
                    2,
                    3,
                    4
                ]
            }
        }
    ]
}
```

### Example of responses

#### 1. Create  Cron Job

```json
{
    "code": 0,
    "result": true,
    "data": {
        "id": 1000067,
        "name": "test API",
        "status": 2,
        "creator": "admin",
        "bk_scope_type": "biz",
        "bk_scope_id": "1",
        "job_plan_id": 1023060,
        "expression": "0 0/5 * * *",
        "global_var_list": [
            {
                "id": 1001101,
                "name": "stringVar",
                "value": "value11112",
                "type": 1
            },
            {
                "id": 1001102,
                "name": "nsVar",
                "value": "nsvalue11112",
                "type": 2
            },
            {
                "id": 1001104,
                "name": "secretVar",
                "value": "secretvalue11112",
                "type": 4
            },
            {
                "id": 1001105,
                "name": "dictVar",
                "value": "([\"var1\"]=1, [\"var2\"]=2)",
                "type": 5
            },
            {
                "id": 1001106,
                "name": "indexArrVar",
                "value": "(2 3 4)",
                "type": 6
            },
            {
                "id": 1001103,
                "name": "hostVar",
                "type": 3,
                "server": {
                    "ip_list": [
                        {
                            "bk_host_id": 101,
                            "bk_cloud_id": 0,
                            "ip": "127.0.0.1"
                        }
                    ]
                }
            }
        ],
        "create_time": 1642045370,
        "last_modify_user": "admin",
        "last_modify_time": 1642045370
    },
    "job_request_id": "xxx"
}
```

#### 2.Update  Cron Job

```json
{
    "code": 0,
    "result": true,
    "data": {
        "id": 1000064,
        "name": "test API",
        "status": 2,
        "creator": "admin",
        "bk_scope_type": "biz",
        "bk_scope_id": "1",
        "job_plan_id": 1023060,
        "expression": "0 0/5 * * *",
        "global_var_list": [
            {
                "id": 1001101,
                "name": "stringVar",
                "value": "value111333312",
                "type": 1
            },
            {
                "id": 1001102,
                "name": "nsVar",
                "value": "nsvalue111333312",
                "type": 2
            },
            {
                "id": 1001104,
                "name": "secretVar",
                "value": "secretvalue111333312",
                "type": 4
            },
            {
                "id": 1001105,
                "name": "dictVar",
                "value": "([\"var1\"]=1, [\"var2\"]=2)",
                "type": 5
            },
            {
                "id": 1001106,
                "name": "indexArrVar",
                "value": "(22 3 4)",
                "type": 6
            },
            {
                "id": 1001103,
                "name": "hostVar",
                "type": 3,
                "server": {
                    "ip_list": [
                        {
                            "bk_host_id": 101,
                            "bk_cloud_id": 0,
                            "ip": "127.0.0.1"
                        }
                    ]
                }
            }
        ],
        "create_time": 1641990674,
        "last_modify_user": "admin",
        "last_modify_time": 1641995052
    }
}
```

### Response Description

{% include '_generic_response.md.j2' %}

#### data

| Fields           | Type   | Never null | Description                                                                                 |
|------------------|--------|------------|---------------------------------------------------------------------------------------------|
| id               | long   | yes        | Cron Job ID                                                                                 |
| name             | string | yes        | Cron job name                                                                               |
| status           | int    | yes        | Cron Job Status                                                                             |
| bk_scope_type    | string | yes        | Resource scope type. Optional values: biz - Business，biz_set - Business Set                 |
| bk_scope_id      | string | yes        | Resource scope ID. Corresponds to bk_scope_type, which means business ID or business set ID |
| job_plan_id      | long   | yes        | Job Plan ID of the job to be executed regularly                                             |
| creator          | string | yes        | Creator                                                                                     |
| create_time      | long   | yes        | Created time, Unix timestamp                                                                |
| last_modify_user | string | yes        | Last modify user                                                                            |
| last_modify_time | long   | yes        | Last modified time, Unix timestamp                                                          |
| expression       | string | no         | Timing rules for Cron Job crontab                                                           |
| execute_time     | long   | no         | Execution time of a single Cron Job execution, Unix timestamp                               |
| global_var_list  | array  | no         | For global variable information, see global_var                                             |

#### global_var

| Fields      | Type   | Never null | Description                                                                                                   |
|-------------|--------|------------|---------------------------------------------------------------------------------------------------------------|
| id          | long   | yes        | Global variable id, unique identification. If the id is empty, then name is used as the unique identification |
| name        | string | yes        | Global variable name                                                                                          |
| description | string | no         | Global variable description                                                                                   |
| type        | int    | yes        | Global variable type                                                                                          |
| required    | int    | yes        | Whether the variable is required in the template/Job Plan                                                     |
| value       | string | no         | Character, password, value of global variable of array type                                                   |
| server      | object | no         | Host type global variable value                                                                               |

#### server

| Fields             | Type   | Never null | Description              |
|--------------------|--------|------------|--------------------------|
| variable           | string | no         | Referenced variable name |
| host_id_list       | array  | no         | Host ID list             |
| ip_list            | array  | no         | Static IP list           |
| dynamic_group_list | array  | no         | Dynamic group ID list    |
| topo_node_list     | array  | no         | Dynamic topo node list   |

#### ip

| Fields      | Type   | Never null | Description |
|-------------|--------|------------|-------------|
| bk_host_id  | long   | yes        | Host ID     |
| bk_cloud_id | int    | yes        | BK-Net ID   |
| ip          | string | yes        | IP Address  |

#### dynamic_group

| Fields | Type   | Never null | Description      |
|--------|--------|------------|------------------|
| id     | string | yes        | Dynamic Group ID |

#### topo_node

| Fields    | Type   | Never null | Description                                                                                |
|-----------|--------|------------|--------------------------------------------------------------------------------------------|
| id        | long   | yes        | Dynamic topo node ID, corresponding to bk_inst_id in CMDB API                              |
| node_type | string | yes        | Dynamic topo node type, corresponding to bk_obj_id in CMDB API, such as "module" and "set" |
